﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace IndoorPosition.Server.Database.Migrations.Migrations
{
    public partial class v001 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Station",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Model = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "产品型号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Board = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "芯片型号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IBeaconName = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "设备名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MeasuredPower = table.Column<double>(type: "double", nullable: false, comment: "功率校验/1米"),
                    TransmissionPower = table.Column<double>(type: "double", nullable: false, comment: "发射功率"),
                    BroadcastInterval = table.Column<int>(type: "int", nullable: false, comment: "广播周期ms"),
                    MAC = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "蓝牙MAC地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UUID = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "UUID")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Major = table.Column<int>(type: "int", nullable: false, comment: "主值"),
                    Minor = table.Column<int>(type: "int", nullable: false, comment: "辅值"),
                    Battery = table.Column<int>(type: "int", nullable: false, comment: "电池容量")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Station", x => x.Id);
                },
                comment: "蓝牙基站")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Position",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    StationId = table.Column<int>(type: "int", nullable: false, comment: "基站ID"),
                    X = table.Column<double>(type: "double", nullable: false, comment: "X坐标"),
                    Y = table.Column<double>(type: "double", nullable: false, comment: "Y坐标")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Position", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Position_Station_StationId",
                        column: x => x.StationId,
                        principalTable: "Station",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "基站位置，使用WGS84 Web Mercator投影坐标")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Position_StationId",
                table: "Position",
                column: "StationId",
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Position");

            migrationBuilder.DropTable(
                name: "Station");
        }
    }
}
